const db = require("../../db/sql");
const {postDao} = require("../../DAO/postData");

function modifyUser(params,res){
    const id = params.userId;
    const { nick_name, sex, role, department, phone, userId, pwd } = params;
    const sql = 'UPDATE userlist SET ? WHERE userId = ?';
    const updatedUser = {
        nick_name,
        sex,
        role,
        department,
        phone,
        userId,
        pwd
    };
    db.query(sql, [updatedUser, id], (error, results) => {
        if (error) {
            console.error(error);
            res.status(500).send({
                error: '服务器内部错误'
            });
        } else if (results.affectedRows === 0) {
            res.status(404).send({
                error: `找不到 ID 为 ${id} 的用户`
            });
        } else {
            res.send({
                message: '用户信息已成功更新'
            });
        }
    });
}
module.exports={
    modifyUser
}
